﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "教师门户 - 本专科教学课表");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		termProp = getProperty("serviceFactory").getBean("termPropertyAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		rs_courseTables = queryNew("course_name,tasktime,taskclsroom,task_week");
		rs_courseTablesForCourse = queryNew("course_name,tasktime,taskclsroom,task_week");
		
		/* 读取学期信息 */
		sql="SELECT 
				term_id,term_prop 
			 FROM 
			 	t_term  
			 WHERE 
			 	SUBSTR(term_prop, 1, 1) = '1' 
				OR 
				SUBSTR(term_prop, 2, 1) = '1'  
			 ORDER BY 
			 	term_id ";
		queryObj = new Query( datasource=application.dnsSlave ); 
		
		rs_term= queryObj.execute( sql=sql ).getResult(); 
		
		
		if (rs_term.recordCount eq 1) {
			/* 没有跨学期课表 */
			termId = rs_term["term_id"][1];
			
			/* 当前学期课表 */
			sql="SELECT 
					d.course_name,a.tasktime,
					case when a.taskclsroom is null then '-' else a.taskclsroom end taskclsroom ,
					a.task_week, c.week_type  
				 FROM 
				 	t_teacher_timetable a 
					INNER JOIN t_course d ON a.cid = d.cid 
					INNER JOIN t_task c ON c.tsk_id = a.task_id 
				 WHERE 
				 	a.tch_id = :teacherId    
					AND 
					a.term_id= :termId  ";	
					
			queryObj = new Query( datasource=application.dnsSlave ); 
			
  			queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
            rs_courseTables = queryObj.execute( sql=sql ).getResult(); 
		}
		
		if (rs_term.recordCount eq 2) {
			
			for (a=1; a LTE rs_term.recordCount; a++) {
				
				termProp.parseProperty(rs_term["term_prop"][a]);
				
				if ( termProp.getRunning() ) {
					
					termId = rs_term["term_id"][a];
					
					/* 当前学期课表 */
					sql="SELECT d.course_name,a.tasktime,
								case when a.taskclsroom is null then '-' else a.taskclsroom end taskclsroom ,
								a.task_week 
						 FROM t_teacher_timetable a 
							  INNER JOIN t_course d ON a.cid = d.cid 
						 WHERE a.tch_id = :teacherId    
							   AND 
							   a.term_id= :termId ";	
							   
					queryObj = new Query( datasource=application.dnsSlave ); 
					
					queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
					
					rs_courseTables = queryObj.execute( sql=sql ).getResult(); 
				}
				
				if ( termProp.getForCourse() ) {
					
					termIdForCourse = rs_term["term_id"][a];
					
					/* 排课学期课表 */
					sql="SELECT d.course_name,a.tasktime,
								case when a.taskclsroom is null then '-' else a.taskclsroom end taskclsroom ,
								a.task_week 
						 FROM t_teacher_timetable a 
							  INNER JOIN t_course d ON a.cid = d.cid 
						 WHERE a.tch_id = :teacherId    
							   AND 
							   a.term_id= :termIdForCourse  ";	
							   
					queryObj = new Query( datasource=application.dnsSlave ); 
					
					queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="termIdForCourse", value=termIdForCourse, cfsqltype="cf_sql_char" );
					
					rs_courseTablesForCourse = queryObj.execute( sql=sql ).getResult(); 
					
				}
				
			}
			
		}
		
		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labCurrent");
		
		if (rs_courseTablesForCourse.recordCount) {
			currentTab = event.getArg("TabID", "labCourseArrange");
		}
		
		targetArgs = structNew();
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('courseTask')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学任务</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 courseTable"></i>个人课表
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labCurrent">class="active"</cfif> id="labCurrent" tabTarget="Current">当前学期</span>
						<cfif rs_courseTablesForCourse.recordCount>
							<span <cfif currentTab eq "labCourseArrange">class="active"</cfif> id="labCourseArrange" tabTarget="CourseArrange">排课学期</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Current" class="tabContent">
					<cfset      sql="SELECT academic_year,academic_term,term_start,term_weeks 
									 FROM t_term  
									 WHERE term_id= :termId " /> 
					<cfset		queryObj = new Query( datasource=application.dnsSlave ) />
					<cfset		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" )/>
					<cfset		rs_term = queryObj.execute( sql=sql ).getResult()/>
				
					<div class="noticeBlock">
						<h3>个人课表</h3>
						<p>
							<span class="img icon16x16 message"></span>
							在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您需要承担课程时间地点安排如下.</p>
						<hr/>
					</div>

					<!-- courseTable -->
					<table class="UICourseTable">
						<thead>
							<tr>
								<td colspan="2" width="2%"></td>
								<td width="14%">星期一</td>
								<td width="14%">星期二</td>
								<td width="14%">星期三</td>
								<td width="14%">星期四</td>
								<td width="14%">星期五</td>
								<td width="14%">星期六</td>
								<td width="14%">星期天</td>
							</tr>
						</thead>
						<tbody>
							<cfloop from="1" to="6" index="lec">
								<tr>
									<cfswitch expression="#lec#">
										<cfcase value="1">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
										<cfcase value="3">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
										<cfcase value="5">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
									</cfswitch>
									<td><cfoutput>#mathAdvice.convertLectureIdxToChinese(lec)#</cfoutput></td>
									<cfloop from="1" to="7" index="wkday">
										<td>
											<cfloop query="rs_courseTables">
                                                       	
                                                            <cfset weekType="" />
                                                            <cfif rs_courseTables.week_type eq "1">
                                                            		 <cfset weekType="(单周上课)" />
                                                                  <cfelseif rs_courseTables.week_type eq "2">
                                                                  	<cfset weekType="(双周上课)" />
                                                            </cfif>
                                                       
                                                       	<cfif rs_courseTables.tasktime eq wkday & "@" & lec & "-1">
													<div class="lecture">
														<!--- 节次 1 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(1节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>
                                                       
												<cfif rs_courseTables.tasktime eq wkday & "@" & lec & "-2">
													<div class="lecture">
														<!--- 节次 2 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(2节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>

												<cfif rs_courseTables.tasktime eq wkday & "@" & lec & "-3">
													<div class="lecture">
														<!--- 节次 3 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(3节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>

												<cfif (rs_courseTables.tasktime eq wkday & "@" & lec & "-4") or (rs_courseTables.tasktime eq wkday & "@" & lec-1 & "-4")>
													<!--- 节次 4 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(2节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>
												
												<cfif (rs_courseTables.tasktime eq wkday & "@" & lec & "-5")>
													<!--- 节次 5 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(2节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
													<cfelseif (rs_courseTables.tasktime eq wkday & "@" & lec-1 & "-5")>
													<div class="lecture">
														<!--- 显示为节次 3 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(3节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>
												
												<cfif (rs_courseTables.tasktime eq wkday & "@" & lec & "-8") or (rs_courseTables.tasktime eq wkday & "@" & lec-1 & "-8") or (rs_courseTables.tasktime eq wkday & "@" & lec-2 & "-8") or (rs_courseTables.tasktime eq wkday & "@" & lec-3 & "-8")>
													<!--- 节次 8 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#rs_courseTables.course_name#</cfoutput>
														<cfif rs_courseTables.taskclsroom neq "-"><br/><cfoutput>#rs_courseTables.taskclsroom#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#rs_courseTables.task_week#</cfoutput></span>(2节)<br/><cfoutput>#weekType#</cfoutput>
													</div>
												</cfif>
												
											</cfloop>
										</td>
									</cfloop>
								</tr>
							</cfloop>
						</tbody>
					</table>
					<!-- /courseTable -->

				</div>
				
				<cfif rs_courseTablesForCourse.recordCount>

					<div id="CourseArrange" class="tabContent">
                        <cfset      sql="SELECT academic_year,academic_term,term_start,term_weeks 
										 FROM t_term 
										 WHERE term_id= :termId " /> 
						<cfset		queryObj = new Query( datasource=application.dnsSlave ) />
                        <cfset		queryObj.addParam( name="termId", value=termIdForCourse, cfsqltype="cf_sql_char" )/>
                        <cfset		rs_term = queryObj.execute( sql=sql ).getResult()/> 
						
						<div class="noticeBlock">
							<h3>个人课表</h3>
							<p>
								<span class="img icon16x16 message"></span>
								在<em><cfoutput>#rs_term.academic_year#</cfoutput>-<cfoutput>#rs_term.academic_term#</cfoutput></em>学期您需要承担课程时间地点安排如下.</p>
							<hr/>
						</div>

						<!-- courseTableForCourse -->
						<table class="UICourseTable">
							<thead>
								<tr>
									<td colspan="2" width="2%"></td>
									<td width="14%">星期一</td>
									<td width="14%">星期二</td>
									<td width="14%">星期三</td>
									<td width="14%">星期四</td>
									<td width="14%">星期五</td>
									<td width="14%">星期六</td>
									<td width="14%">星期天</td>
								</tr>
							</thead>
							<tbody>
								<cfloop from="1" to="6" index="lec">
									<tr>
										<cfswitch expression="#lec#">
											<cfcase value="1">
												<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
											</cfcase>
											<cfcase value="3">
												<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
											</cfcase>
											<cfcase value="5">
												<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
											</cfcase>
										</cfswitch>
										<td><cfoutput>#mathAdvice.convertLectureIdxToChinese(lec)#</cfoutput></td>
										<cfloop from="1" to="7" index="wkday">
											<td>
                                        			<cfloop query="rs_courseTablesForCourse">
                                                       		
                                                                 <cfif rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-1">
														<div class="lecture">
															<!--- 节次 2 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(1)</span><br/>
														</div>
													</cfif>
	
													<cfif rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-2">
														<div class="lecture">
															<!--- 节次 2 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(2)</span><br/>
														</div>
													</cfif>

													<cfif rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-3">
														<div class="lecture">
															<!--- 节次 3 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(3)</span><br/>
														</div>
													</cfif>

													<cfif (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-4") or (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec-1 & "-4")>
														<!--- 节次 4 --->
														<div class="lecture">
															<!--- 显示为节次 2 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(2)</span><br/>
														</div>
													</cfif>
												
													<cfif (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-4")>
														<!--- 节次 5 --->
														<div class="lecture">
															<!--- 显示为节次 2 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(2)</span><br/>
														</div>
														<cfelseif (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec-1 & "-4")>
														<div class="lecture">
															<!--- 显示为节次 3 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(3)</span><br/>
														</div>
													</cfif>
												
													<cfif (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec & "-8") or (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec-1 & "-8") or (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec-2 & "-8") or (rs_courseTablesForCourse.tasktime eq wkday & "@" & lec-3 & "-8")>
														<!--- 节次 8 --->
														<div class="lecture">
															<!--- 显示为节次 2 --->
															<cfoutput>#rs_courseTablesForCourse.course_name#</cfoutput>
															<cfif rs_courseTablesForCourse.taskclsroom neq "-"><br/><cfoutput>#rs_courseTablesForCourse.taskclsroom#</cfoutput></cfif>
															<br/><span class="number"><cfoutput>#rs_courseTablesForCourse.task_week#</cfoutput>(2)</span><br/>
														</div>
													</cfif>
												
												</cfloop>
											</td>
										</cfloop>
									</tr>
								</cfloop>
							</tbody>
						</table>
						<!-- /courseTableForCourse -->

					</div>
				</cfif>
				
			</div>
		</li>
	</ul>
</div>

